package ru.justplay.core;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Alexey Andreev
 */
public class GameFeatureImpl implements GameFeature, GameRepository {
    private Map<String, Game> games = new HashMap<String, Game>();

    @Override
    public void addGame(Game game) {
        if (games.containsKey(game.getName())) {
            throw new IllegalArgumentException("Game already registered: " + game.getName());
        }
        games.put(game.getName(), game);
    }

    public Game getGame(String name) {
        return games.get(name);
    }

    @Override
    public List<Game> getGames() {
        return new ArrayList<Game>(games.values());
    }
}
